//
//  MTAboutMeViewController.swift
//  MT
//
//  Created by ooops on 2020/3/13.
//  Copyright © 2020 张强. All rights reserved.
//

import UIKit
import MTCategory

class MTAboutMeViewController: BaseViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        title = "关于觅颜"
        // Do any additional setup after loading the view.
        setupUI()
        makeConstraint()
        values()
        userAgreement()
    }
    
    private func values() {
        let infoDict = Bundle.main.infoDictionary!
        let minorVersion = infoDict["CFBundleShortVersionString"]//版本号（内部标示）
        
        versionLabel.text = "v " + (minorVersion as! String)
        
        ipcNumLabel.text = "浙ICP备20003045号-1"
    }
    
    private func setupUI() {
        view.addSubview(iconView)
        view.addSubview(versionLabel)
        view.addSubview(userAgrementLabels)
        view.addSubview(copyrightLabel)
        view.addSubview(ipcNumLabel)
    }
    
    private func userAgreement() {
        
        let attributeText = NSMutableAttributedString(string: "隐私条款&用户协议")
        
        attributeText.setTextUnderline(YYTextDecoration.init(style: .single), range: attributeText.string.nsrange(of: "隐私条款")[0])
        attributeText.setUnderlineColor(UIColor.theme.main, range: attributeText.string.nsrange(of: "隐私条款")[0])
        
        attributeText.setTextUnderline(YYTextDecoration.init(style: .single), range: attributeText.string.nsrange(of: "用户协议")[0])
        attributeText.setUnderlineColor(UIColor.theme.main, range: attributeText.string.nsrange(of: "用户协议")[0])
        
        attributeText.setFont(PingFangSCLightFont(14), range: NSRange(location: 0, length: attributeText.string.count))
        
        attributeText.addAttributes([NSAttributedString.Key.foregroundColor : UIColor.white], range: NSRange(location: 0, length: attributeText.string.count))
        
        attributeText.setTextHighlight(attributeText.string.nsrange(of: "隐私条款")[0], color: .white, backgroundColor: nil) { (v, attribute, range, rect) in
            let c = MTMineWebViewController()
            c.selectValue = 1
            self.navigationController?.pushViewController(c, animated: true)
        }
        
        attributeText.setTextHighlight(attributeText.string.nsrange(of: "用户协议")[0], color: .white, backgroundColor: nil) { (v, attribute, range, rect) in
            let c = MTMineWebViewController()
            c.selectValue = 0
            self.navigationController?.pushViewController(c, animated: true)
        }
        
        userAgrementLabels.attributedText = attributeText
    }
    
    private func makeConstraint() {
        iconView.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.centerY.equalToSuperview().offset(-120)
            make.width.height.equalTo(100)
        }
        
        versionLabel.snp.makeConstraints { (make) in
            make.top.equalTo(iconView.snp.bottom).offset(20)
            make.centerX.equalToSuperview()
        }
        
        ipcNumLabel.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.bottom.equalToSuperview().offset(-20)
        }
        
        copyrightLabel.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.bottom.equalTo(ipcNumLabel.snp.top).offset(-2)
        }
        
        userAgrementLabels.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.bottom.equalTo(copyrightLabel.snp.top).offset(-2)
        }
        
    }
    
    lazy var iconView: UIImageView = {
        let imageV = UIImageView()
        imageV.image = UIImage(named: "Icon-60")
        imageV.layer.cornerRadius = 5
        imageV.layer.masksToBounds = true
        return imageV
    }()
    
    
    lazy var versionLabel: UILabel = {
        let l = UILabel()
        l.font = PingFangSCLightFont(14)
        l.textColor = .white
        return l
    }()
    
    lazy var userAgrementLabels: YYLabel = {
        let l = YYLabel()
        l.font = PingFangSCLightFont(14)
        l.textColor = .white
        l.sizeToFit()
        return l
    }()
    
    lazy var copyrightLabel: UILabel = {
        let l = UILabel()
        l.font = PingFangSCLightFont(14)
        l.textColor = .white
        l.text = "Copyright © 2020 觅颜"
        l.sizeToFit()
        return l
    }()
    
    lazy var ipcNumLabel: UILabel = {
        let l = UILabel()
        l.font = PingFangSCLightFont(14)
        l.textColor = .white
        l.sizeToFit()
        return l
    }()
    
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */
    
//    let infoDict = Bundle.main.infoDictionary!
//    let minorVersion = infoDict["CFBundleShortVersionString"]//版本号（内部标示）
//    return minorVersion as! String

}
